import { Injectable } from '@angular/core';
import { gw_code_g, gw_schedule } from '@core';
import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';

export const STARTUP_TYPES = [
  { label: '手工启动', value: 'manual' },
  { label: '自启动', value: 'auto' },
  { label: '禁用', value: 'disable' }
];

export const EXECUTE_TYPES = [
  { label: '类名称', value: 'class' },
  { label: 'Bean名称', value: 'bean' },
  { label: '请求地址', value: 'url' }
];

@Injectable()
export class AfSystemService {
  constructor(private http: _HttpClient) {}

  public queryFileType() {
    return this.getLookup('upload_file_business');
  }

  public getLookup(type: string): Observable<any> {
    return this.http.get(`${gw_code_g}/lookup/${type}`);
  }

  public getScheduleGroup(): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/group/get/all`);
  }

  public saveScheduleGroup(body: any): Observable<any> {
    return this.http.post(`${gw_schedule}/schedule/group/save`, body);
  }
  public deleteScheduleGroup(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/group/delete/${code}`);
  }

  public getScheduleJob(forced: boolean = false): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/get/reload?forced=${forced}`);
  }

  public restartAllJob(): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/restart/all`);
  }

  public startJobByGroup(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/start/group/${code}`);
  }

  public stopJobByGroup(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/stop/group/${code}`);
  }

  public startJob(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/start/${code}`);
  }
  public stopJob(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/stop/${code}`);
  }

  public executeJob(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/execute/${code}`);
  }

  public disableJob(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/disabled/${code}`);
  }

  public deleteJob(code: any): Observable<any> {
    return this.http.get(`${gw_schedule}/schedule/job/delete/${code}`);
  }

  public saveJob(body: any): Observable<any> {
    return this.http.post(`${gw_schedule}/schedule/job/save`, body);
  }

  public getScheduleJobLogUrl() {
    return `${gw_schedule}/schedule/job/log/get`;
  }
}
